﻿using System;
using System.Windows;
using System.Windows.Threading;

namespace TallyJ
{
  ///<summary>
  /// Extensions specific to WPF
  ///</summary>
  public static class Extensions
  {
    private static readonly Action EmptyDelegate = delegate { };
    private static readonly Action SimpleDelegate = delegate { };

    ///<summary>Refresh this element using Dispatcher Invoke
    ///</summary>
    ///<param name="uiElement"></param>
    public static void DispatcherRefresh(this UIElement uiElement)
    {
      if (uiElement == null) return;

      uiElement.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
    }

    ///<summary>Run an action on this element
    ///</summary>
    ///<param name="input"></param>
    ///<param name="text"></param>
    ///<param name="action"></param>
    public static void DispatcherAction(this DispatcherObject input, Action action)
    {
      if (input == null) return;
      input.Dispatcher.Invoke(DispatcherPriority.Render, action);
    }
  }
}